//
//  ImageCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/4/21.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "ImageCell.h"

@implementation ImageCell{
    QXLable *labTitle;
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        labTitle=[[QXLable alloc]initTitle];
        labTitle.textAlignment=NSTextAlignmentCenter;
        [self.contentView addSubview:labTitle];
        [labTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.contentView);
            make.top.equalTo(self.contentView).with.offset(10);
        }];
        
        self.imageV=[[UIImageView alloc]init];
        [self.contentView addSubview:self.imageV];
        [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentView);
        }];
        
        
        self.GalleryRecommend=[[UIImageView alloc]init];
        [self.contentView addSubview:self.GalleryRecommend];
        [self.GalleryRecommend mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.equalTo(self.imageV);
            make.size.mas_equalTo(CGSizeMake(39, 39));
        }];
    }
    return self;
}

- (void)setGEModel:(GalleryExtraModel *)GEModel{
    _GEModel=GEModel;
    labTitle.text=GEModel.Name;
    WS(weakSelf);
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:GEModel.Picture] placeholderImage:[UIImage imageNamed:@"big_loding"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        float   height=SCREEN_WIDTH/image.size.width*image.size.height;
        if (weakSelf.GEModel.picHeight!=height) {
            weakSelf.GEModel.picHeight=height;
            if (weakSelf.changeHeight) {
                weakSelf.changeHeight(height);
            }
        }
        self.imageV.image=image;
    }];
    
    [labTitle mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.contentView).with.offset(10);
    }];
    
    [self.imageV mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(labTitle.mas_bottom).with.offset(10);
        make.left.equalTo(self.contentView).with.offset(10);
        make.height.mas_equalTo(@(GEModel.picHeight));
        make.right.equalTo(self.contentView).with.offset(-10);
    }];
}

@end
